﻿#include "Mario.h"
#include "Resource.h"
//#include "Global.h"
#include "MarioManager.h"
#include "Bullet.h"
#include "QuadTree.h"

/**--------------------------------------------------------
*Description : Constructor
*Method name : Mario
*Parameters :  float x, float y, bool isAi
*Return value :
--------------------------------------------------------**/
Mario::Mario(LPDIRECT3DDEVICE9 d3ddv,  LPDIRECT3DSURFACE9 BackBuffer, LPD3DXSPRITE SpriteHandler, float x, float y, MarioManager* Game_Mario, int Object_State, int Direction)
{
	this->game_Mario = Game_Mario;
	this->d3ddv = d3ddv;
	this->BackBuffer = BackBuffer;
	this->SpriteHandler = SpriteHandler;

	_spriteSmall = new Sprite(SpriteHandler, ResourceMng::GetInst(d3ddv, BackBuffer)->GetTexture(L"..\\Resources\\Images\\MarioSmall.png"), 100, 0);
	_spriteBig = new Sprite(SpriteHandler, ResourceMng::GetInst(d3ddv, BackBuffer)->GetTexture(L"..\\Resources\\Images\\MarioBig.png"), 100, 0);
	_spriteBullet = new Sprite(SpriteHandler, ResourceMng::GetInst(d3ddv, BackBuffer)->GetTexture(L"..\\Resources\\Images\\MarioBullet.png"), 100, 0);
	_spriteLight = new Sprite(SpriteHandler, ResourceMng::GetInst(d3ddv, BackBuffer)->GetTexture(L"..\\Resources\\Images\\MarioSmall2.png"), 100, 0);
	_sprite = _spriteSmall;

	_turnLeft = false;		//ben trai
	_isJumping = false;		//khong nhay
	//_isAi = isAi;
	_isSmall = true;		//mario nho		
	_isShoot = false;		//khong ban duoc
	_isHasStar = false;
	_isMoveDown = false;

	_x = x;
	_y = y;

	_xOld = _x;
	_yOld = _y;

	_xPosOld = _x;

	_vx = 0;
	_vy = 0;

	_accelX = 0;
	_accelY = 0;

	_rectOld = _rectBond;



	timeBullet = 0;
	timeTransferState = 0;
	countFrame = 0;

	/*if(_isAi)
	{
	_vx = MARIO_VX;
	}*/


	collisionObjectList = new list<Object*>;

	//object_State = MS_NORMAL;
	object_State = Object_State;
	direction = Direction;
	if (object_State == MS_NORMAL)
	{
		if (direction == 1)			//mario nho
		{
			_sprite = _spriteSmall;
			_isSmall = true;
		} 
		else if (direction == 21)	//mario to
		{
			_sprite = _spriteBig;
			_isSmall = false;
		}
		else if (direction == 22)	//mario to, co bullet
		{
			_sprite = _spriteBullet;
			_isSmall = false;
			_isShoot = true;
		}
	} 
	else if (object_State == MS_HASSTAR)
	{
		timeProtect = 0;
		countFrame = 0;
		_isHasStar = true;
		if (direction == 1)			//mario nho
		{
			_sprite = _spriteSmall;
			_isSmall = true;
		} 
		else if (direction == 21)	//mario to
		{
			_sprite = _spriteBig;
			_isSmall = false;
		}
		else if (direction == 22)	//mario to, co bullet
		{
			_sprite = _spriteBullet;
			_isSmall = false;
			_isShoot = true;
		}
	}
	else if (object_State == MS_PROTECT)
	{
		timeProtect = 0;
		countFrame = 0;
		
		_isHasStar = false;
		if (direction == 1)			//mario nho
		{
			_sprite = _spriteSmall;
			_isSmall = true;
		} 
		else if (direction == 21)	//mario to
		{
			_sprite = _spriteBig;
			_isSmall = false;
		}
		else if (direction == 22)	//mario to, co bullet
		{
			_sprite = _spriteBullet;
			_isSmall = false;
			_isShoot = true;
		}
	}
	else if (object_State == MS_DIE)
	{
		_sprite = _spriteSmall;
		//if (_turnLeft == true)
		if (direction == 1)		//left
		{
			_sprite->SetFrame(6,6);
		} 
		else if (direction == 2)	//right
		{
			_sprite->SetFrame(4,4);
		}
		_vy = -1.5;
		_accelY = GRAVITY;
	} 
	else if (object_State == MS_SMALLTOBIG)
	{
		//_y = _y + 30;
		_isSmall = false;
		timeTransferState = 0;
		countFrame = 0;
		_sprite = _spriteSmall;
		//if (_turnLeft == true)
		if (direction == 1)		//left
		{
			_turnLeft = true;
			//_sprite->SetFrame(9, 11);
		} 
		else if (direction == 2)	//right
		{
			_turnLeft = false;
			//_sprite->SetFrame(0, 2);
		}
	}
	else if (object_State == MS_BIGTOSMALL)
	{
		_y = _y - 30;
		_isSmall = true;
		timeTransferState = 0;
		countFrame = 0;
		_sprite = _spriteBig;
		//if (_turnLeft == true)
		if (direction == 1)		//left
		{
			_turnLeft = true;
			//_sprite->SetFrame(9, 11);
		} 
		else if (direction == 2)	//right
		{
			_turnLeft = false;
			//_sprite->SetFrame(0, 2);
		}
	}
	else if (object_State == MS_BULLETTOSMALL)
	{
		_y = _y - 30;
		_isSmall = true;
		_isShoot = false;
		timeTransferState = 0;
		countFrame = 0;
		_sprite = _spriteBig;
		//if (_turnLeft == true)
		if (direction == 1)		//left
		{
			_turnLeft = true;
			//_sprite->SetFrame(9, 11);
		} 
		else if (direction == 2)	//right
		{
			_turnLeft = false;
			//_sprite->SetFrame(0, 2);
		}
	}
	else if (object_State == MS_BIGTOBULLET)
	{
		_isSmall = false;
		_isShoot = true;
		timeTransferState = 0;
		countFrame = 0;
		_sprite = _spriteBig;
		//if (_turnLeft == true)
		if (direction == 1)		//left
		{
			_turnLeft = true;
			//_sprite->SetFrame(9, 11);
		} 
		else if (direction == 2)	//right
		{
			_turnLeft = false;
			//_sprite->SetFrame(0, 2);
		}
	}
	

}


/**--------------------------------------------------------
*Description : Destructor
*Method name : Mario
*Parameters :   
*Return value :
--------------------------------------------------------**/
Mario::~Mario(void)
{
	/*delete _sprLeft;
	delete _sprRight;
	delete _sprJumpLeft;
	delete _sprJumpRight;*/
	//if (_sprite)
	//{
	//	delete _sprite;
	//	//_sprite = NULL;
	//}
	if (collisionObjectList){
		delete collisionObjectList;
		//collisionObjectList = NULL;
	}
}


/**--------------------------------------------------------
*Description : Update mario theo thoi gian
*Method name : Update
*Parameters :  int time
*Return value :void
--------------------------------------------------------**/
//void Mario::Update(int _ScreenWidth, int _ScreenHeight, int time, list<Object*> *ObjectList, DxInput *input)
//{
//
//	collisionObjectList->clear();
//	Object* obj;
//	list<Object*>::iterator i;
//	for (i = ObjectList->begin(); i != ObjectList->end(); i++)
//	{
//		obj = *i;
//		if (obj->GetTypeObject() == OBJECT_LAND)
//		{
//			collisionObjectList->push_back(obj);
//		}
//	}
//
//
//	this->ProcessInput(input);
//
//	//velocity
//	_vx += _accelX * time;
//
//	//if(_vx  > 0)
//	//{
//	//	_vx -= ACCEL_X * time;
//	//	//if(_vx < 0) _vx = 0;
//	//	if(_vx < 0) 
//	//	{
//	//		_vx = 0;
//	//		_accelX = 0;
//	//	}
//	//}
//	//else
//	//{
//	//	_vx += ACCEL_X * time;
//	//	//if(_vx > 0) _vx = 0;
//	//	if(_vx > 0) 
//	//	{
//	//		_vx = 0;
//	//		_accelX = 0;
//	//	}
//	//}
//
//	//chuyen dong cham lai do khong nhan phim
//	/*if(_vx * _accelX < 0 && _accelX < 0)
//	{
//	_vx -= ACCEL_X * time;
//	if(_vx < 0) 
//	{
//	_vx = 0;
//	_accelX = 0;
//	}
//	}
//	else if(_vx * _accelX < 0 && _accelX > 0)
//	{
//	_vx += ACCEL_X * time;
//	if(_vx > 0) 
//	{
//	_vx = 0;
//	_accelX = 0;
//	}
//	}*/
//
//
//	if(_vx < 0)
//	{
//		_accelX = ACCEL_X / 2;
//	}
//	else if(_vx > 0)
//	{
//		_accelX = -ACCEL_X / 2;
//	}
//	else
//	{
//		_accelX = 0;
//	}
//
//
//	if (_vx > MARIO_VX_MAX)
//	{
//		_vx = MARIO_VX_MAX;
//	}
//	if (_vx < -MARIO_VX_MAX)
//	{
//		_vx = - MARIO_VX_MAX;
//	}
//	_x += _vx * time + 1.0/2 * _accelX * time * time;
//	ResetRect();
//
//	if(collisionObjectList->size() > 0)
//	{
//		Object* obj;
//		list<Object*>::iterator i;
//		for(i = collisionObjectList->begin(); i != collisionObjectList->end(); i++)
//		{
//			obj = *i;
//			if(Collision::RectVsRect(this->GetBond(), obj->GetBond()))
//			{
//
//				_accelX = 0;
//				_vx = 0;
//
//				if (_turnLeft)
//				{
//					_x = obj->GetBond().left + obj->GetSprite()->texture->_Width;//GetX() - this->GetSprite()->texture->_Width;//this->GetBond().left;
//					//_y = this->GetBond().right - this->GetSprite()->texture->_Width;
//					_y = abs(obj->GetBond().bottom - this->GetSprite()->texture->_Height);
//
//					//_sprite->SetFrame(9,10);
//				}
//				else
//				{
//					_x = obj->GetBond().left - this->GetSprite()->texture->_Width;
//					//_y = obj->GetBond().left - this->GetSprite()->texture->_Width;
//					_y = abs(obj->GetBond().bottom - this->GetSprite()->texture->_Height);
//
//					//_sprite->SetFrame(0,1);
//				}
//
//
//				//_x = obj->GetX() - this->GetSprite()->texture->_Width;//this->GetBond().left;
//			}
//		}
//		ResetRect();
//	}
//	/*if (_isJumping == false)
//	{
//	_vy = MARIO_VY;
//
//	}*/
//
//	_accelY = GRAVITY;
//	_vy += _accelY * time;
//	_y += _vy * time + 1.0/2 * _accelY * time * time;
//
//	ResetRect();
//
//
//	//kiem tra va cham nam tren gach, da
//	if(collisionObjectList->size() > 0)
//	{
//		Object* obj;
//		list<Object*>::iterator i;
//		for(i = collisionObjectList->begin(); i != collisionObjectList->end(); i++)
//		{
//			obj = *i;
//			if(Collision::RectVsRect(this->GetBond(), obj->GetBond()))
//			{
//				if (_isJumping == true && _vy < 0)
//				{
//					_accelY = GRAVITY;
//					_vy = 0;
//					_y = obj->GetBond().bottom;
//				}
//			}
//			if(this->GetBond().bottom <= obj->GetBond().bottom && this->GetBond().left < obj->GetBond().right && this->GetBond().right > obj->GetBond().left)
//
//				if(obj->GetY() - this->_sprite->texture->_Height < this->_y)
//				{
//					//if(obj->ID==29)				//Nếu là cờ
//					//	y=obj->y+TILE_SIZE*10-height;
//					//else
//					//this->SetY(obj->GetY() - this->GetSprite()->texture->_Height);
//					//_y = 0;
//					/*isJumming=false;
//					timeJumped=0;
//					vy=0;*/
//					_vy = 0;
//					_isJumping = false;
//					_y = obj->GetY() - this->GetSprite()->texture->_Height;//BOTTOM - _sprite->texture->_Height - 1;
//					//_x = obj->GetY() - this->GetSprite()->texture->_Height;
//
//
//				}
//
//				//if (isSmall == true)
//				//{
//				//	if(obj->GetY() - this->_sprite->texture->_Height < this->_y)
//				//	{
//				//		//if(obj->ID==29)				//Nếu là cờ
//				//		//	y=obj->y+TILE_SIZE*10-height;
//				//		//else
//				//		//this->SetY(obj->GetY() - this->GetSprite()->texture->_Height);
//				//		//_y = 0;
//				//		/*isJumming=false;
//				//		timeJumped=0;
//				//		vy=0;*/
//				//		_vy = 0;
//				//		_isJumping = false;
//				//		_y = obj->GetY() - this->GetSprite()->texture->_Height;//BOTTOM - _sprite->texture->_Height - 1;
//				//		//_x = obj->GetY() - this->GetSprite()->texture->_Height;
//
//
//				//	}
//				//} 
//				//else
//				//{
//				//	if(obj->GetY() - this->_spriteBig->texture->_Height < this->_y)
//				//	{
//				//		//if(obj->ID==29)				//Nếu là cờ
//				//		//	y=obj->y+TILE_SIZE*10-height;
//				//		//else
//				//		//this->SetY(obj->GetY() - this->GetSprite()->texture->_Height);
//				//		//_y = 0;
//				//		/*isJumming=false;
//				//		timeJumped=0;
//				//		vy=0;*/
//				//		_vy = 0;
//				//		_isJumping = false;
//				//		_y = obj->GetY() - this->GetSprite()->texture->_Height;//BOTTOM - _sprite->texture->_Height - 1;
//				//		//_x = obj->GetY() - this->GetSprite()->texture->_Height;
//
//
//				//	}
//				//}
//
//
//		}
//		ResetRect();
//	}
//
//
//	if(_y >= BOTTOM - _sprite->texture->_Height)//_sprRight->texture->_Height
//	{
//		_vy = 0;
//		_isJumping = false;
//		_y = BOTTOM - _sprite->texture->_Height - 1;
//	}
//
//
//	if(_isAi)
//	{
//		if(_vx > 0)
//		{
//			TurnRight();
//		}
//		else
//		{
//			TurnLeft();
//		}
//
//		if(_x >= _ScreenWidth - _sprite->texture->_Width)
//		{
//			TurnLeft();
//		}
//		else if(_x <= 0)
//		{
//			TurnRight();
//		}
//
//	}
//	/*else
//	{
//	if(_x >= _ScreenWidth - _sprRight->texture->_Width)
//	{
//	_x = _ScreenWidth - _sprRight->texture->_Width;
//	}
//	else if (_x <= 0)
//	{
//	_x = 0;
//	}
//	}*/
//
//	if (_accelX * _vx < 0)
//	{
//		if (_vx > - ACCEL_X/1.5 && _vx < ACCEL_X/1.5)
//		{
//			_vx = 0;
//			_accelX = 0;
//		}
//	}
//
//	//sprite
//	//if(_vx != 0 )//|| _vy != 0)
//	//_curSprite->Update(time);
//	_sprite->Update(time);
//
//
//
//}

void Mario::Update(list<Object*>* staObjs, list<Object*>* dynObjs, DxInput* input, float time)
{

	switch(object_State)
	{
	case MS_NORMAL:
		{
			//kiem tra Phim nhan
			this->ProcessInput(input);
			this->Move(staObjs, dynObjs, time);
			this->UpdateNormal(staObjs, dynObjs, input, time);
			
			//su dung khi load map
			if (_isSmall == true)
			{
				direction = 1;
			} 
			else
			{
				if (_isShoot == false)
				{
					direction = 21;
				} 
				else
				{
					direction = 22;
				}
			}
		}
		break;

	case MS_DIE:
		//_x += _vx * time;
		//Saave map
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}

		_vy += _accelY * time;
		_y += _vy * time + 1/2 * _accelY * time *time;
		if (_y > 600)
		{
			ChangeState(MS_REMOVE);
			if (game_Mario->num_Life == 0)
			{
				game_Mario->ChangeState(GS_GAMEOVER);
			}
			else
				game_Mario->ChangeState(GS_REPLAY);
		}
		ResetRect();
		//_sprite->Update(gameTime);
		break;

	case MS_CREPTPINE:
		//_x += _vx * time;
		//Saave map
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}

		_vy += _accelY * time;
		_y += _vy * time + 1/2 * _accelY * time *time;
		if (_y > 600)
		{
			ChangeState(MS_REMOVE);
			game_Mario->ChangeState(GS_SUB_STAGE);
		}
		ResetRect();
		break;

	case MS_GOUPPINE:
		//_x += _vx * time;
		//Saave map
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}

		_vy += _accelY * time;
		_y += _vy * time + 1/2 * _accelY * time *time;
		if (_y < _yPosOld - 100)
		{
			ChangeState(MS_NORMAL);
			//game_Mario->ChangeState(GS_SUB_STAGE);
		}
		ResetRect();
		break;

	case MS_INTOPINE:
		//Saave map
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}

		_vx += _accelX * time;
		_x += _vx * time + 1/2 * _accelX * time * time;

		if (_x > _xPosOld + 32)
		{
			ChangeState(MS_REMOVE);
			game_Mario->ChangeState(GS_RETURN_STAGE);
		} 
		 
		ResetRect();
		break;

	case MS_SMALLTOBIG:
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}
		timeTransferState += time;
		if (timeTransferState > 40)
		{
			timeTransferState = 0;
			countFrame++;
			if (countFrame % 2 != 0)		//frame le
			{
				_y = _y - 30;
				_sprite = _spriteBig;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(8,9);
				} 
				else
				{
					_sprite->SetFrame(1,2);
				}
			}
			else								//frame chan
			{
				_y = _y + 30;
				_sprite = _spriteSmall;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(10,11);
				} 
				else
				{
					_sprite->SetFrame(0,1);
				}

			}
			if (countFrame > 8)
			{
				ChangeSprite(_spriteBig);
				ChangeState(MS_NORMAL);
			}

		}
		ResetRect();
		break;

	case MS_BIGTOSMALL:
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}
		timeTransferState += time;
		if (timeTransferState > 40)
		{
			timeTransferState = 0;
			countFrame++;
			if (countFrame % 2 != 0)		//frame le
			{
				_y = _y + 30;
				_sprite = _spriteSmall;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(10,11);
				} 
				else
				{
					_sprite->SetFrame(0,1);
				}

			}
			else								//frame chan
			{
				_y = _y - 30;
				_sprite = _spriteBig;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(8,9);
				} 
				else
				{
					_sprite->SetFrame(1,2);
				}

			}
			if (countFrame > 8)
			{
				ChangeSprite(_spriteSmall);
				ChangeState(MS_PROTECT);
			}

		}
		ResetRect();
		break;

	case MS_BULLETTOSMALL:
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}
		timeTransferState += time;
		if (timeTransferState > 40)
		{
			timeTransferState = 0;
			countFrame++;
			if (countFrame % 2 != 0)		//frame le
			{
				_y = _y + 30;
				_sprite = _spriteSmall;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(10,11);
				} 
				else
				{
					_sprite->SetFrame(0,1);
				}

			}
			else								//frame chan
			{
				_y = _y - 30;
				_sprite = _spriteBullet;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(8,9);
				} 
				else
				{
					_sprite->SetFrame(1,2);
				}

			}
			if (countFrame > 8)
			{
				ChangeSprite(_spriteSmall);
				ChangeState(MS_PROTECT);
				//ChangeState(MS_NORMAL);
			}

		}
		ResetRect();
		break;

	case MS_BIGTOBULLET:
		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}
		timeTransferState += time;
		if (timeTransferState > 40)
		{
			timeTransferState = 0;
			countFrame++;
			if (countFrame % 2 != 0)		//frame le
			{
				_sprite = _spriteBullet;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(8,9);
				} 
				else
				{
					_sprite->SetFrame(1,2);
				}
			}
			else								//frame chan
			{
				_sprite = _spriteBig;
				if (_turnLeft == true)
				{
					_sprite->SetFrame(8,9);
				} 
				else
				{
					_sprite->SetFrame(1,2);
				}
			}
			if (countFrame > 8)
			{
				ChangeSprite(_spriteBullet);
				ChangeState(MS_NORMAL);
			}
		}
		ResetRect();
		break;

	case MS_PROTECT:
		ProcessInput(input);
		Move(staObjs, dynObjs, time);

		if (_turnLeft == true)
		{
			direction = 1;
		} 
		else
		{
			direction = 2;
		}

		timeProtect += time;
		if (timeProtect > 40)
		{
			timeProtect = 0;
			countFrame++;
			if (countFrame % 2 != 0)		//frame le
			{
				_sprite = _spriteLight;

			}
			else								//frame chan
			{
				_sprite = _spriteSmall;

			}
			if (countFrame > 43)
			{
				ChangeSprite(_spriteSmall);
				ChangeState(MS_NORMAL);
			}
		}
		ResetRect();
		break;

	case MS_HASSTAR:
		ProcessInput(input);
		Move(staObjs, dynObjs, time);
		UpdateNormal(staObjs, dynObjs, input, time);
		timeProtect += time;
		if (timeProtect > 40)
		{
			timeProtect = 0;
			countFrame++;
			if (countFrame % 2 != 0)		//frame le
			{
				if (_isSmall == true)
				{
					_sprite = _spriteLight;
				} 
				else
				{
					_sprite = _spriteBig;
				}


			}
			else								//frame chan
			{
				if (_isSmall == true)
				{
					_sprite = _spriteSmall;
				} 
				else
				{
					_sprite = _spriteBullet;
				}


			}
			if (countFrame > 243)
			{
				_isHasStar = false;
				if (_isSmall == true)
				{
					ChangeSprite(_spriteSmall);
				} 
				else
				{
					if (_isShoot == true)
					{
						ChangeSprite(_spriteBullet);
					} 
					else
					{
						ChangeSprite(_spriteBig);
					}
				}
				ChangeState(MS_NORMAL);
			}
		}
		ResetRect();
		break;
	}




	//thuc hien update sprite
	//if(_vx != 0 )//|| _vy != 0)
	//_curSprite->Update(time);
	_sprite->Update(time);



}

void Mario::UpdateNormal(list<Object*>* staObjs, list<Object*>* dynObjs, DxInput* input, float time)
{
	timeBullet += time;			//sau 1 khoang time mario moi ban bullet

	/*if (game_Mario->num_Score == 1000)
	{
		game_Mario->num_Life++;
		game_Mario->scoreArr[NUMBER_LIFE]->Update(game_Mario->num_Life);
		game_Mario->num_Score = 0;
	}*/

	Object* obj;
	list<Object*>::iterator i;

	for (i = staObjs->begin(); i != staObjs->end(); i++)
	{
		obj = *i;
		//if (obj->GetID() == 24 && obj->object_State == 2)
		//{
		//	if ((this->GetBond().bottom <= obj->GetBond().top) && (Collision::RectVsRect(this->GetBond(), obj->GetBond())))		//trang thai cong chuoi
		//	{
		//		if (_isMoveDown == true)
		//		{
		//			game_Mario->ChangeState(GS_REPLAY);
		//			_isMoveDown = false;
		//		}
		//	}
		//} 
		 
		if (Collision::RectVsRect(this->GetBond(), obj->GetBond()))
		{
			switch(obj->GetID())
			{
			case 42:	//pirhana
				if (obj->object_State != IS_REMOVE)
				{
					if (_isHasStar == false)	//khong co sao
					{
						if (_isSmall == true)
						{
							ChangeState(MS_DIE);
							obj->object_State = ES_REMOVE;
						}
						else
						{
							_isSmall = true;
							if (_isShoot == true)
							{
								ChangeState(MS_BULLETTOSMALL);
							}
							else
							{
								ChangeState(MS_BIGTOSMALL);
							}
							_isShoot = false;
							obj->object_State = ES_REMOVE;
						}
					} 
					else						//co sao
					{
						obj->object_State = ES_REMOVE;
					}

				}
				break;

			case 41:	//coin
				if (obj->object_State == IS_IDLE)
				{
					 
					game_Mario->num_Coin++;
					game_Mario->scoreArr[COIN]->Update(game_Mario->num_Coin);
					game_Mario->InfoScore(200, obj->GetX(), obj->GetY() - 40);
					game_Mario->scoreArr[SCORE]->Update(game_Mario->num_Score);

					game_Mario->dxAudio->PlaySoundW(game_Mario->coinSound);
					obj->ChangeState(IS_REMOVE);
				}
				break;

			

			case 51:		//checkpoint
				game_Mario->mapManager->saveMario->object_State = this->object_State;
				game_Mario->mapManager->saveMario->direction = this->direction;

				game_Mario->ChangeState(GS_NEXT_STAGE);
				break;
			}


		}
	}

	for (i = dynObjs->begin(); i != dynObjs->end(); i++)
	{
		obj = *i;
		if (Collision::RectVsRect(this->GetBond(), obj->GetBond()))
		{
			switch (obj->GetID())
			{
			case 43:	//va cham an nam mang: moving 
			//case 431:	//va cham an nam mang: moving 
			//case 432:	//va cham an nam mang: moving 
				if (obj->object_State == IS_MOVING)
				{
					game_Mario->num_Life++;	//tang 1 mang
					game_Mario->scoreArr[NUMBER_LIFE]->Update(game_Mario->num_Life);
					game_Mario->dxAudio->PlaySound(game_Mario->bonusRiseSound);
					obj->ChangeState(IS_REMOVE);
				}
				break;

			case 44:	//va cham an sao: moving 
				if (obj->object_State == IS_MOVING)
				{
					game_Mario->num_Life++;	//tang 1 mang
					game_Mario->scoreArr[NUMBER_LIFE]->Update(game_Mario->num_Life);
					game_Mario->dxAudio->PlaySound(game_Mario->bonusRiseSound);
					obj->ChangeState(IS_REMOVE);
					_isHasStar = true;
					ChangeState(MS_HASSTAR);
				}
				break;

			case 45:	//va cham an nam : moving, hoa:ready
			//case 491:	//va cham an nam : moving, hoa:ready
			//case 492:	//va cham an nam : moving, hoa:ready
			//case 50:	//va cham an nam : moving, hoa:ready
				if (obj->object_State == IS_MOVING || obj->object_State == IS_READY)
				{
					game_Mario->InfoScore(1000, obj->GetX(), obj->GetY() - 40);	//an nam tang 1000 diem
					game_Mario->scoreArr[SCORE]->Update(game_Mario->num_Score);
					game_Mario->dxAudio->PlaySound(game_Mario->bonusRiseSound);
					obj->ChangeState(IS_REMOVE);
					if (this->_isSmall == true)
					{
						_isSmall = false;
						ChangeState(MS_SMALLTOBIG);
					}
					else
					{
						ChangeState(MS_BIGTOBULLET);
						_isShoot = true;
					}
				}
				break;

			case 11:		//va cham goomba
				if (_isHasStar == false)		//khong co sao
				{
					if (obj->object_State == ES_ACTIVING)
					{
						if (_vy > 0)
						{
							game_Mario->InfoScore(100, obj->GetX(), obj->GetY() - 40);
							game_Mario->scoreArr[SCORE]->Update(game_Mario->num_Score);
							game_Mario->dxAudio->PlaySound(game_Mario->mipSound);
							obj->ChangeState(ES_DIED);

							_vy = - 1.0; //giam enemy rui nhay len
						}
						else
						{
							if (_isSmall == true)
							{
								game_Mario->num_Life--;
								game_Mario->scoreArr[NUMBER_LIFE]->Update(game_Mario->num_Life);
								game_Mario->dxAudio->PlaySound(game_Mario->deathSound);
								ChangeState(MS_DIE);
							}
							else
							{
								_isSmall = true;
								if (_isShoot == true)
								{
									ChangeState(MS_BULLETTOSMALL);
								}
								else
								{
									ChangeState(MS_BIGTOSMALL);
								}
								_isShoot = false;
							}

						}
					}
				} 
				else
				{
					obj->ChangeState(ES_FALL);
				}
				break;

			case 12:		//va cham koopa
				if (_isHasStar == false)		//khong co sao
				{
					if (obj->object_State == ES_ACTIVING)
					{
						if (_vy > 0)
						{

							game_Mario->InfoScore(100, obj->GetX(), obj->GetY() - 40);
							//game_Mario->num_Score += 100;
							game_Mario->scoreArr[SCORE]->Update(game_Mario->num_Score);

							game_Mario->dxAudio->PlaySound(game_Mario->mipSound);

							obj->ChangeState(ES_STOP);
							//obj->object_State = ES_REMOVE;

							_vy = - 1.0; //giam enemy rui nhay len
						}
						else
						{
							if (_isSmall == true)
							{
								game_Mario->num_Life--;
								game_Mario->scoreArr[NUMBER_LIFE]->Update(game_Mario->num_Life);
								game_Mario->dxAudio->PlaySound(game_Mario->deathSound);
								/*_x = 100;
								_y = 100;*/
								ChangeState(MS_DIE);
							}
							else
							{
								_isSmall = true;

								if (_isShoot == true)
								{
									ChangeState(MS_BULLETTOSMALL);
								}
								else
								{
									ChangeState(MS_BIGTOSMALL);
								}
								_isShoot = false;
								//obj->object_State = ES_REMOVE;
							}

						}
					}
					else if (obj->object_State == ES_STOP)
					{
						RECT rectLeft;
						rectLeft.left = obj->GetX();
						rectLeft.right = rectLeft.left + 1;
						rectLeft.top = obj->GetY();
						rectLeft.bottom = rectLeft.top + obj->GetSprite()->texture->_Height;

						//if (_vx > 0 || _turnLeft == false)	//di chuyen ve phai
						//{
						//	obj->ChangeState(ES_MOVE_SHELL_RIGHT);
						//}
						//else if (_vx < 0 || _turnLeft == true)	//di chuyen ve trai
						//{
						//	obj->ChangeState(ES_MOVE_SHELL_LEFT);
						//}

						if (Collision::RectVsRect(this->GetBond(), rectLeft) == true)	//di chuyen ve phai
						{
							obj->ChangeState(ES_MOVE_SHELL_RIGHT);
						}
						else  	//di chuyen ve trai
						{
							obj->ChangeState(ES_MOVE_SHELL_LEFT);
						}
						_vy = -1.5;
					}
					else if (obj->object_State == ES_MOVE_SHELL_LEFT || obj->object_State == ES_MOVE_SHELL_RIGHT)
					{
						if (_vy > 0)
						{
							obj->ChangeState(ES_STOP);
							_vy = -2.0;
						}
						else
						{
							if (_isSmall == true)
							{
								game_Mario->num_Life--;
								game_Mario->scoreArr[NUMBER_LIFE]->Update(game_Mario->num_Life);
								game_Mario->dxAudio->PlaySound(game_Mario->deathSound);
								/*_x = 100;
								_y = 100;*/
								ChangeState(MS_DIE);
							}
							else
							{
								_isSmall = true;
								if (_isShoot == true)
								{
									ChangeState(MS_BULLETTOSMALL);
								}
								else
								{
									ChangeState(MS_BIGTOSMALL);
								}
								_isShoot = false;
								obj->object_State = ES_REMOVE;
							}
						}
					}
				} 
				else	//da an sao
				{
					obj->ChangeState(ES_FALL);
				}
				break;

				
			}
		}
	}
}



void Mario::Move(list<Object*>* staObjs, list<Object*>* dynObjs, float time)
{
	Object* obj;
	list<Object*>::iterator i;

	 
	//Xet va cham theo X
	_vx += _accelX * time;
	if (_vx > MARIO_VX_MAX)
	{
		_vx = MARIO_VX_MAX;
	}
	else if (_vx < -MARIO_VX_MAX)
	{
		_vx = - MARIO_VX_MAX;
	}
	_x += _vx * time + 1.0/2 * _accelX * time * time;
	ResetRect();

	//kiem tra va cham voi da, gach theo X
	 
	for(i = staObjs->begin(); i != staObjs->end(); i++)
	{
		obj = *i;
		if (obj->GetID() >= 21 && obj->GetID() <= 29 && obj->GetID() != 26) //gach, da, dat, ong,...
		{
			if(Collision::RectVsRect(this->GetBond(), obj->GetBond()))
			{
				//xu ly mario chui len tu map phu
				if (obj->GetID() == 29)// && game_Mario->issubmap == true)
				{
					if (_turnLeft == false)
					{
						game_Mario->mapManager->saveMario->object_State = this->object_State;
						game_Mario->mapManager->saveMario->direction = this->direction;

						ChangeState(MS_INTOPINE);
						
						//game_Mario->ChangeState(GS_SUB_STAGE);

					}
				}
				else
				{
					_accelX = 0;
					_vx = 0;
					_x = _xOld;
				}
				

				
			}
			//ResetRect();
		}

	}



	//Xet va cham theo Y
	_accelY = GRAVITY;
	_vy += _accelY * time;
	_y += _vy * time + 1.0/2 * _accelY * time * time;
	_rectOld = _rectBond;
	ResetRect();

	//Ngan mario rot xuong ma van con nhay duoc
	if (_vy > 0)
	{
		_isJumping = true;
	}

	collisionObjectList->clear();
	for (i = staObjs->begin(); i != staObjs->end(); i++)
	{
		obj = *i;
		if (obj->GetID() >= 21 && obj->GetID() <= 29) //gach, da, dat, ong,...
		{
			if(Collision::RectVsRect(this->GetBond(), obj->GetBond()))
			{
				collisionObjectList->push_back(obj);

				if(_rectOld.bottom<obj->GetBond().bottom)
					if(obj->GetY() - this->_sprite->texture->_Height < _y)
					{
						//if(obj->ID==29)				//Nếu là cờ
						//	y=obj->y+TILE_SIZE*10-height;
						//else
						//	y=obj->y-height;
						/*isJumming=false;
						timeJumped=0;
						vy=0;*/
						
						//Xu ly chui cong
						if (obj->GetID() == 24 && obj->object_State == 2)
						{
							RECT rect_temp;
							rect_temp.left = obj->GetBond().left + 30;
							rect_temp.right = rect_temp.left + 4;
							rect_temp.top = obj->GetBond().top;
							rect_temp.bottom = obj->GetBond().bottom;

							if (_isMoveDown == true && Collision::RectVsRect(this->GetBond(), rect_temp))
							{
								_isMoveDown == false;

								//Luu trang thai mario sau khi chui cong
								game_Mario->mapManager->saveMario->object_State = this->object_State;
								game_Mario->mapManager->saveMario->direction = this->direction;

								ChangeState(MS_CREPTPINE);

								//game_Mario->ChangeState(GS_SUB_STAGE);

								//Thiet dat trang thai cho Pine de mario khong chui duoc nua.
								/*obj->object_State = 1;*/
							}
						}


						_y=obj->GetY() - this->_sprite->texture->_Height;
						_vy = 0;
						_isJumping = false;
					}

				
				if (_isJumping == true && _vy < 0)
				{
					//if (Collision::RectVsRect(_rectHead, obj->GetBond()))
					//Xet va cham voi cac block
					switch(obj->GetID())
					{
					case  21:	//gach
						if (obj->object_State == BS_NORMAL)
						{
							if (this->_isSmall == true)
							{
								obj->ChangeState(BS_MOVEUP);
								game_Mario->dxAudio->PlaySound(game_Mario->bumpSound);
							}
							else
							{
								obj->ChangeState(BS_BREAKING);
								game_Mario->dxAudio->PlaySoundW(game_Mario->brickBreakSound);
								game_Mario->InfoScore(50, obj->GetX(), obj->GetY() - 40);
								game_Mario->scoreArr[SCORE]->Update(game_Mario->num_Score);


							}
						}
						break;

					case 25:	//gach dau hoi
						if (obj->object_State == BS_NORMAL)
						{
							obj->ChangeState(BS_MOVEUP);
						}

						break;
					case 26:	//gach an
						if (obj->object_State == BS_NORMAL)
						{
							obj->ChangeState(BS_MOVEUP);
						}

						break;

					case 27:	//gach 5 coin
						if (obj->object_State == BS_NORMAL)
						{
							obj->ChangeState(BS_MOVEUP);
						}

						break;
					case 28:	//gach sao
						if (obj->object_State == BS_NORMAL)
						{
							obj->ChangeState(BS_MOVEUP);
						}

						break;
					 
					}

					CollisionOnTop(obj, staObjs, dynObjs); //Xet va cham dung gach thi an tien, chet quai ben tren						

					_accelY = GRAVITY;
					_vy = 0;
					_y = obj->GetBond().bottom;
				}


			}


		}

		ResetRect();
	}

	//Duyệt danh sách va chạm theo chiều dọc, để không bị rơi
	//if(collisionObjectList->size()>0)
	//{
	//	Object* obj;
	//	list<Object*>::iterator i;
	//	for(i=collisionObjectList->begin();i!=collisionObjectList->end();i++)
	//	{
	//		obj=*i;
	//		if(_rectOld.bottom<obj->GetBond().bottom)
	//			if(obj->GetY() - this->_sprite->texture->_Height < _y)
	//			{
	//				//if(obj->ID==29)				//Nếu là cờ
	//				//	y=obj->y+TILE_SIZE*10-height;
	//				//else
	//				//	y=obj->y-height;
	//				/*isJumming=false;
	//				timeJumped=0;
	//				vy=0;*/
	//				_y=obj->GetY() - this->_sprite->texture->_Height;
	//				_vy = 0;
	//				_isJumping = false;
	//				//_y = obj->GetY() - this->GetSprite()->texture->_Height;
	//			}
	//			
	//				
	//	}
	//	ResetRect();
	//}

	 

	_xOld = _x;
	_yOld = _y;

	if(_y >= BOTTOM - _sprite->texture->_Height)
	{
		//xu ly mario roi xuong ho
		/*_vx = 0;
		_accelX = 0;
		_vy = 0;
		_accelY = 0;
		_x = 100;
		_y = 400;*/
		game_Mario->ChangeState(GS_REPLAY);
	}

	//chuyen dong cham lai do khong nhan phim
	if(_vx < 0)
	{
		_accelX = ACCEL_X / 2;
	}
	else if(_vx > 0)
	{
		_accelX = -ACCEL_X / 2;
	}
	else
	{
		_accelX = 0;
	}

	//tao chuyen dong dung lai
	if (_accelX * _vx < 0)
	{
		if (_vx > -ACCEL_X*2 && _vx < ACCEL_X*2)
		{
			_vx = 0;
			_accelX = 0;
		}
	}
}

void Mario::CollisionOnTop(Object* obj,list<Object*>* staObjs,list<Object*>* dynObjs)
{
	if((obj->GetID()==21||obj->GetID()==25||obj->GetID()==26||obj->GetID()==27 || obj->GetID()==28)) //gach: 21, gach dau hoi: 25, gach an: 26	, gach chua 5 coin: 27	
	{
		RECT rTop;					//Rect ngay trên viên gạch
		list<Object*>::iterator k;
		Object* objTop;
		rTop.left=obj->GetBond().left;			
		rTop.right=obj->GetBond().right;
		rTop.top=obj->GetBond().top-32;//TILE_SIZE;	
		rTop.bottom=obj->GetBond().top;
		for (k=staObjs->begin();k!=staObjs->end();k++)
		{
			objTop=*k;
			if(objTop->GetID()==41||objTop->GetID()==46||objTop->GetID()==47)			//tien hien, tien an, 5tien an
				if(Collision::RectVsRect(rTop,objTop->GetBond()))
				{
					if(objTop->object_State == IS_IDLE) 
					{
						if (objTop->GetID() == 47)
						{
							objTop->container = obj;
						}
						//if (obj->GetID() == 21)	//gach:21, co 5 dong tien
						//{
						//	objTop->ChangeState(IS_ACTIVING);
						//}
						//else
						objTop->ChangeState(IS_ACTIVING);
						//EatCoin(objTop->x,objTop->y);

						game_Mario->num_Coin++;
						game_Mario->scoreArr[COIN]->Update(game_Mario->num_Coin);
						game_Mario->InfoScore(200, obj->GetX(), obj->GetY() - 40);
						game_Mario->scoreArr[SCORE]->Update(game_Mario->num_Score);

						game_Mario->dxAudio->PlaySoundW(game_Mario->coinSound);
						

					}

				}
		}
		for(k=dynObjs->begin();k!=dynObjs->end();k++)
		{
			objTop=*k;
			switch(objTop->GetID())
			{
			case 11:	//goomba
			case 12:	//koopa
				if(Collision::RectVsRect(rTop,objTop->GetBond()))
				{
					objTop->ChangeState(ES_FALL);
				}
				break;

			case 43: //lifemushroom: 43 nam mang
				if(Collision::RectVsRect(rTop,objTop->GetBond()) && objTop->object_State == IS_IDLE)
				{
					objTop->ChangeState(IS_ACTIVING);
				}
				break;

			case 44: //star: 44  
				if(Collision::RectVsRect(rTop,objTop->GetBond()) && objTop->object_State == IS_IDLE)
				{
					objTop->ChangeState(IS_ACTIVING);
				}
				break;

			case 45:	//power: 45, nam lon, hoa
				if(Collision::RectVsRect(rTop,objTop->GetBond()) && objTop->object_State == IS_IDLE)
				{
					if (this->_isSmall == true)
					{
						objTop->ChangeState(IS_ACTIVING);
					}
					else
						objTop->ChangeState(IS_FLOWER);
				}
				break;
			}
		}
	}
}


/**--------------------------------------------------------
*Description : Render mario
*Method name : Render
*Parameters :  
*Return value :void
--------------------------------------------------------**/
void Mario::Render()
{

	/*D3DXVECTOR2 rotate;
	rotate.x =  _x ;
	rotate.y =  _y ;

	D3DXVECTOR2 translation;
	translation.x = rotate.x - 400;
	translation.y = rotate.y - 550;

	D3DXMATRIX t1;
	D3DXMatrixAffineTransformation2D(
	&t1,
	1.5f,
	&rotate,
	0,
	NULL
	);
	_spriteHandler->SetTransform(&t1);*/


	//_curSprite->Render((int)_x, (int)_y);
	_sprite->Render((int)_x, (int)_y);
	//if (isSmall == true)
	//{

	//} 
	//else
	//{
	//	//_sprite->Render((int)_x, (int)_y);
	//	_spriteBig->Render((int)_x, (int)_y);
	//}

}

void Mario::ProcessInput(DxInput *input)
{
	//printf("FPS: %f", this->GetFPS());

	_isMoveDown = false;

	//Dieu khien nhay
	int temp = input->GetKeyDown();
	switch (temp)
	{
	case DIK_UP:
	case DIK_SPACE:
		this->Jump();
		game_Mario->dxAudio->PlaySoundW(game_Mario->jumpSound);
		trace(L"Ban dang nhan phim Up hoac Space!");
		break;
	case DIK_DOWN:
		_isMoveDown = true;
		trace(L"Ban dang nhan phim Up hoac Space!");
		break;
	}


	//State
	//Nhan phim va giu
	if (input->IsKeyDown(DIK_RIGHT))
	{
		this->TurnRight();
		trace(L"Ban dang nhan phim Right!");
	}	
	else if (input->IsKeyDown(DIK_LEFT))
	{
		this->TurnLeft();
		trace(L"Ban dang nhan phim Left!");
	}
	//else if (input->IsKeyDown(DIK_DOWN))
	//{
	//	//this->TurnLeft();
	//	_isMoveDown = true;
	//	trace(L"Ban dang nhan phim Down!");
	//}
	else
	{
		this->Reset();
	}

	if (input->IsKeyDown(DIK_E))
	{
		if (timeBullet > 500 && _isShoot == true)
		{
			Object* bullet;
			Object* bullet2;
			if (_turnLeft == true)
			{
				bullet = new Bullet(d3ddv, BackBuffer, SpriteHandler, this->GetX(), this->GetY() + _sprite->texture->_Height/2, true);
				bullet2 = new Bullet(d3ddv, BackBuffer, SpriteHandler, this->GetX() + _sprite->texture->_Width/2, this->GetY() + _sprite->texture->_Height/2, true);
			}
			else
			{
				bullet = new Bullet(d3ddv, BackBuffer, SpriteHandler, this->GetX() + _sprite->texture->_Width, this->GetY() + _sprite->texture->_Height/2, false);
				bullet2 = new Bullet(d3ddv, BackBuffer, SpriteHandler, this->GetX() + _sprite->texture->_Width/2, this->GetY() + _sprite->texture->_Height/2, false);
			}
			//bullet->ChangeState()
			game_Mario->quadTree->Add(bullet, false);
			game_Mario->quadTree->Add(bullet2, false);
			trace(L"Ban dang nhan phim E");
			timeBullet = 0;
		}

	}
	//this->ResetJump();
}

/**--------------------------------------------------------
*Description : mario nhay sang trai
*Method name : TurnLeft
*Parameters :  
*Return value :void
--------------------------------------------------------**/
void Mario::TurnLeft()
{
	_turnLeft = true;
	if (_isJumping == true)
	{
		//_sprite->SetFrame(9, 9);
		if (_isSmall == true)
		{
			_sprite->SetFrame(8, 8);
		}
		else
		{
			_sprite->SetFrame(9, 9);
		}
	}
	else
	{
		//_sprite->SetFrame(6, 9);
		if (_isSmall == true)
		{
			_sprite->SetFrame(9, 11);
		}
		else
		{
			_sprite->SetFrame(6, 9);

		}
	}

	//_vx = - MARIO_VX;
	_accelX = - ACCEL_X * 2;//1.5;//MARIO_VX;

}


/**--------------------------------------------------------
*Description : mario nhay sang phai
*Method name : TurnRight
*Parameters :  
*Return value :void
--------------------------------------------------------**/
void Mario::TurnRight()
{
	_turnLeft = false;
	if (_isJumping == true)
	{
		//_sprite->SetFrame(0, 1);
		if (_isSmall == true)
		{
			_sprite->SetFrame(2, 2);
		}
		else
		{
			_sprite->SetFrame(0, 1);
		}
	}

	else
	{
		//_sprite->SetFrame(1, 4);
		if (_isSmall == true)
		{
			_sprite->SetFrame(0, 2);
		}
		else
		{
			_sprite->SetFrame(1, 4);
		}
	}

	//_vx = MARIO_VX;
	_accelX = ACCEL_X * 2;//1.5;//MARIO_VX;

}


/**--------------------------------------------------------
*Description : mario nhay len
*Method name : Jump
*Parameters :  
*Return value :void
--------------------------------------------------------**/
void Mario::Jump()
{
	if(!_isJumping)
	{
		_isJumping = true;
		if (_turnLeft == true)
		{
			//_sprite->SetFrame(9, 9);
			if (_isSmall == true)
			{
				_sprite->SetFrame(8, 8);
			}
			else
			{
				_sprite->SetFrame(9, 9);
			}

		}
		else
		{
			//_sprite->SetFrame(0, 1);
			if (_isSmall == true)
			{
				_sprite->SetFrame(2, 2);
			}
			else
			{
				_sprite->SetFrame(0, 1);
			}
		}

		_vy = - MARIO_VY;
	}
}


/**--------------------------------------------------------
*Description : Mario tro ve ban dau
*Method name : Reset
*Parameters :  
*Return value :void
--------------------------------------------------------**/
void Mario::Reset()
{

	if (_turnLeft == true)
	{
		if (_isJumping == true)
		{
			//_sprite->SetFrame(9, 9);
			if (_isSmall == true)
			{
				_sprite->SetFrame(8, 8);
			}
			else
			{
				_sprite->SetFrame(9, 9);
			}

		} 
		else
		{
			//_sprite->SetFrame(8, 9);
			if (_isSmall == true)
			{
				_sprite->SetFrame(10, 11);
			}
			else
			{
				_sprite->SetFrame(8, 9);
			}

		}

	}
	else 
	{
		if (_isJumping == true)
		{
			//_sprite->SetFrame(0, 1);
			if (_isSmall == true)
			{
				_sprite->SetFrame(2, 2);
			}
			else
			{
				_sprite->SetFrame(0, 1);
			}

		} 
		else
		{
			//_sprite->SetFrame(1, 2);
			if (_isSmall == true)
			{
				_sprite->SetFrame(0, 1);
			}
			else
			{
				_sprite->SetFrame(1, 2);
			}

		}

	}


}

D3DXVECTOR2 Mario::GetPosition()
{
	D3DXVECTOR2 position;
	position.x = _x;
	position.y = _y;
	return position;
}


void Mario::ResetRect()
{
	//dang them vao
	_rectBond.left = _x;
	_rectBond.right = _rectBond.left + _sprite->texture->_Width;
	_rectBond.top = _y;
	_rectBond.bottom = _rectBond.top + _sprite->texture->_Height;

	_rectHead.left = _x + 7;
	_rectHead.right = _rectHead.left + _sprite->texture->_Width;
	_rectHead.top = _y;
	_rectHead.bottom = _rectHead.top + _sprite->texture->_Height / 4;

	 
}

void Mario::ResetJump()
{
	if (_isJumping == false && _vx == 0)
	{
		if (_turnLeft == true)
		{
			_sprite->SetFrame(9,9);
		}
		else
		{
			_sprite->SetFrame(0,0);
		}
	}
}

void Mario::ChangeSprite(Sprite* sprite)
{
	_sprite = sprite;
}

void Mario::ChangeState(int state)
{
	object_State = state;
	switch (object_State)
	{
	case MS_NORMAL:
		break;

	case MS_DIE:
		if (_turnLeft == true)
		{
			_sprite->SetFrame(6,6);
		} 
		else
		{
			_sprite->SetFrame(4,4);
		}
		_vy = -1.5;
		_accelY = GRAVITY;
		break;

	case MS_CREPTPINE:			//chui cong
		
		_accelY = GRAVITY/10;
		break;

	case MS_GOUPPINE:			//chui cong len
		//_accelY = -GRAVITY/10;
		_vy = -MARIO_VY;
		_accelY = GRAVITY;
		_yPosOld = _y;
		break;

	case MS_INTOPINE:			//chui vao cong
		_accelX = ACCEL_X * 2;
		_xPosOld = _x;
		break;

	case MS_REMOVE:
		
		break;

	case MS_SMALLTOBIG:
		timeTransferState = 0;
		countFrame = 0;
		break;

	case MS_BIGTOSMALL:
		timeTransferState = 0;
		countFrame = 0;
		break;

	case MS_BIGTOBULLET:
		timeTransferState = 0;
		countFrame = 0;
		break;

	case MS_BULLETTOSMALL:
		timeTransferState = 0;
		countFrame = 0;
		break;

	case MS_PROTECT:
		timeProtect = 0;
		countFrame = 0;
		break;

	case MS_HASSTAR:
		timeProtect = 0;
		countFrame = 0;
		break;
	}
}